import java.util.*;

public class 单词规律2 {
    public boolean wordPattern(String pattern, String s) {
        //同构字符串同理, 哈希表映射变成了字符对应字符串即可
        Map<Character,String> map1 = new HashMap<>();
        Map<String,Character> map2 = new HashMap<>();
        String[] str = s.split(" ");
        if(str.length != pattern.length()){
            return false;
        }
        for(int i = 0;i < pattern.length();i++){
            char x = pattern.charAt(i);
            String y = str[i];
            if((map1.containsKey(x) && !map1.get(x).equals(y)) || (map2.containsKey(y) && !map2.get(y).equals(x))){
                return false;
            }
            map1.put(x,y);
            map2.put(y,x);
        }
        return true;
    }
}
